package com.jusda.service.insert;

import com.jusda.api.task.DataGenerateTask;
import com.jusda.entity.Order;
import com.jusda.mapper.OrderJpaResp;
import com.jusda.util.ThreadPoolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ExecutorService;

/**
 * @author:y022 07/05/2022 09:39
 * @description:
 */
@Service
public class InsertService {
    @Autowired
    private OrderJpaResp orderJpaResp;
    private final static ExecutorService executorService = ThreadPoolUtil.getExecutorService();

    public void batchGenerate(int size) {
        List<Order> orders = Order.batchGenerate(size);
        List<Order> orders1 = orders.subList(0, size/2);
        List<Order> orders2 = orders.subList(size/2, orders.size()-1);

        executorService.execute(new DataGenerateTask(orderJpaResp, orders1));
        executorService.execute(new DataGenerateTask(orderJpaResp, orders2));
    }

}


